package com.ctbu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ctbu.entity.FinancialProduct;
import com.ctbu.mapper.FinancialProductMapper;
import com.ctbu.service.FinancialProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctbu.tools.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 金融衍生品表，包含衍生品的ID、名称和价格 服务实现类
 * </p>
 *
 * @author tanyan
 * @since 2024年06月27日
 */
@Service
public class FinancialProductServiceImpl extends ServiceImpl<FinancialProductMapper, FinancialProduct> implements FinancialProductService {

    @Autowired
    private FinancialProductMapper financialProductMapper;
    @Override
    public ResponseResult<Object> selectList(int pageNum, int pageSize, String productName) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        LambdaQueryWrapper<FinancialProduct> wrapper = new LambdaQueryWrapper<>();
        if (StringUtils.isNotBlank(productName)){
            //模糊查询
            wrapper.like(FinancialProduct::getProductName,productName);
        }
        List<FinancialProduct> list = financialProductMapper.selectList(wrapper);
        //将查询结果封装
        PageInfo<FinancialProduct> pageInfo = new PageInfo<>(list);
        return ResponseResult.success(pageInfo,"查询成功");


    }
}
